package com.yzk.auction.dao;

import com.yzk.auction.entity.Users;
import com.yzk.auction.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;

/**
 * Author: 园中葵小组成员
 * Description:用户相关数据交互，不涉及逻辑代码
 */
public class UserDao {
    private DataSource dataSource = JDBCUtils.getDataSource();
    private Users users = null;

    /**
     * 根据电话号和密码查找用户信息
     * @param tel 电话
     * @param pwd 密码
     * @return User对象
     */
    public Users findByTelPwd(String tel,String pwd){
        QueryRunner qr = new QueryRunner(dataSource);
        try {
            users = qr.query("select * from tb_users where user_tel=? and user_pwd=?",
                    new BeanHandler<>(Users.class), new Object[]{tel,pwd});
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return users;
    }

}
